<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  </head>

  <body>
    <button class="btn1">发送get</button>
    <button class="btn2">发送delete</button>
    <button class="btn3">发送post</button>
    <button class="btn4">发送put请求</button>
    <script>
      document.querySelector(".btn1").onclick = async function () {
        let { data } = await axios.get("/getdata", {
          params: {
            name: "zhangsan",
            age: 22,
          },
          timeout: 2000,
        });
        console.log(data);
      };

      document.querySelector(".btn3").onclick = async function () {
        let { data } = await axios.post(
          "/getpostdata",
          {
            name: "zhangsan1",
            age: 23,
          },
          { timeout: 2000 }
        );
        console.log(data);
      };
    </script>
  </body>
</html>
